package com.itheima.config;


import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import javax.sql.DataSource;

//TODO:配置SqlSessionFactory和MapperScannerConfigurer
//2、在MybatisConfig配置类中构建SqlSessionFactoryBean和MapperScannerConfigurer
//
public class MybatisConfig {
    @Bean
    public SqlSessionFactoryBean getSession(DataSource ds){
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        //设置连接池
        factoryBean.setDataSource(ds);
        //设置包扫描pojo
        factoryBean.setTypeAliasesPackage("com.itheima.domain");
        return factoryBean;

    }
    @Bean
    public MapperScannerConfigurer getMapperScannerConfigurer(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        //设置dao层的接口扫描
        msc.setBasePackage("com.itheima.mapper");
        return msc;
    }

}
